//
// Created by Administrator on 2023/7/29.
//

// Definition for a binary tree node.
# include <iostream>

using namespace std;

struct TreeNode {
    int val;
    TreeNode *left;
    TreeNode *right;

    TreeNode() : val(0), left(nullptr), right(nullptr) {}

    TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}

    TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
};

class Solution {
public:
    bool checkTree(TreeNode *root) {
        int count = root->val;
        count -= root->left == nullptr? 0 :root->left->val;
        count -= root->right== nullptr?0:root->right->val;
        return count == 0;
    }
};

int main() {
    TreeNode n1(10), n2(4, nullptr, nullptr), n3(6, nullptr, nullptr);
    n1.left = &n2, n1.right = &n3;
    Solution s;
    cout << s.checkTree(&n1) << endl;
}